<template>
	<view class="page">
		
		<view class="nav_bar flex_r_between">
			<view class="nav_bar_icon flex_r_around" @click="$util.back()">
				<u-icon name="arrow-left" color="#FFF" size="40rpx"></u-icon>
			</view>
			
			<!-- 动态：1=待审核,2=审核通过,3=审核不通过 -->
			<view class="nav_bar_btn flex_center">
				<view class="nav_bar_item flex_r_around accept" @click="beforeAccept" v-if="data.status == 2 || data.status == 1">
					<text>拒绝</text>
				</view>
				<view class="nav_bar_item flex_r_around agree" @click="onAgree" v-if="data.status == 1 || data.status == 3">
					<text>同意</text>
				</view>
			</view>
		</view>
		
		<view class="box flex_r_around">

			<!--  -->
			<view class="video" v-if="data.video" @click="onVideo">
				<video id="myVideo" :src="data.video" :autoplay="true" :loop="true" :danmu-list="danmuList" enable-danmu
					:show-play-btn="false" :show-fullscreen-btn="false" @play="is_play = true"
					@pause="is_play = false"></video>

				<view class="play_icon flex_r_around" v-if="!is_play">
					<u-icon name="play-right-fill" size="36rpx" color="#FFF"></u-icon>
				</view>
			</view>

			<swiper v-else :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiper">
				<swiper-item v-for="(item,index) in data.images" :key="index" class="item flex_r_around">
					<image :src="item" mode="widthFix"></image>
				</swiper-item>
			</swiper>
		</view>


		<view class="icon flex_c">
			<view class="item flex_c" @click="showLogin">
				<image :src="$util.prefix('public/home_icon1.png')" mode="aspectFill"></image>
				<text>{{ data.like_num || 0 }}</text>
			</view>
			<view class="item flex_c" @click="show_eval = true">
				<image :src="$util.prefix('public/home_icon2.png')" mode="aspectFill"></image>
				<text>{{ data.discuss_num || 0 }}</text>
			</view>
			<view class="item flex_c" @click="showLogin">
				<image :src="$util.prefix('public/home_icon3.png')" mode="aspectFill"></image>
				<text>{{ data.collect_num || 0 }}</text>
			</view>
			<view class="item flex_c" @click="showLogin">
				<image :src="$util.prefix('public/home_icon4.png')" mode="aspectFill"></image>
				<text>{{ data.collect_num || 0 }}</text>
			</view>
		</view>

		<view class="container" @click="showLogin">
			<view class="flex_center">
				<view class="address flex_center">
					<image :src="$util.prefix('public/address.png')" mode="aspectFill"></image>
					<text>{{ data.location_desc || '' }}</text>
				</view>
			</view>
			<view class="user flex_center">
				<view class="avatar">
					<image :src="data.avatar" mode="aspectFill"></image>
				</view>
				<view class="nickname hidden">
					{{ data.nickname || '' }}
				</view>

				<view class="follow flex_r_around">
					<u-icon name="plus" color="#FFF" bold size="24rpx"></u-icon>
				</view>

			</view>

			<view class="content_text hidden_3">
				{{ data.content }}
			</view>
		</view>

		<u-popup :show="show_eval" @close="show_eval = false" round="32rpx">
			<view class="popup flex_c">
				<view class="block">
					<scroll-view scroll-y="true" @scrolltolower="onReach">
						<view class="list flex_center" v-for="(item,index) in list" :key="index">
							<view class="avatar">
								<image :src="item.avatar" mode="aspectFill">
								</image>
							</view>
							<view class="list_content">
								<view class="nickname flex_center" @click="showLogin">
									<text class="hidden">{{ item.nickname || '' }}</text>
									<view v-if="data.user_id == item.user_id">作者</view>
								</view>
								<view class="content" @click="showLogin">{{ item.content }}
								</view>
								<view class="text flex_center" @click="showLogin">
									<view>
										<uni-dateformat :date="item.create_time" format="MM-dd"></uni-dateformat>
									</view>
									<!-- <view>27.31 km 昌平区</view> -->
									<text>回复</text>
								</view>

								<view class="child flex_center" v-for="(val,i) in item.child">
									<view class="child_avatar">
										<image :src="val.avatar" mode="aspectFill">
										</image>
									</view>
									<view class="child_content" @click.stop="showLogin">
										<view class="nickname flex_center">
											<text class="hidden">{{ val.nickname || '' }} </text>
											<text class="hidden" v-if="val.to_nickname"> 回复
												{{ val.to_nickname || '' }}</text>
											<view v-if="data.user_id == val.user_id">作者</view>
										</view>
										<view class="content">{{ val.content || '' }}</view>
										<view class="text flex_center">
											<view>
												<uni-dateformat :date="val.create_time" format="MM-dd"></uni-dateformat>
											</view>
											<!-- <view>27.31 km 昌平区</view> -->
											<text>回复</text>
										</view>
									</view>
								</view>

								<view class="more flex_center"
									v-if="item.child_num >= item.child.length && item.child_num!=0">
									<view class="border"></view>
									<view class="more_block flex_center" v-if="item.child_num > item.child.length"
										@click="showMore(item,index)">
										<text>展开{{ item.child_num }}条回复</text>
										<u-icon name="arrow-down" color="#999999" size="20rpx"></u-icon>
									</view>
									<view class="more_block flex_center" v-if="item.child_num == item.child.length"
										@click="hideMore(item,index)">
										<text>收起</text>
										<u-icon name="arrow-up" color="#999999" size="20rpx"></u-icon>
									</view>
								</view>
							</view>
						</view>

						<view style="height: 30rpx;"></view>
					</scroll-view>
				</view>

				<view class="input">
					<view class="inp flex_center">
						<input ref="evalInput" type="text" placeholder="友善言论，文明发言" placeholder-class="input-placeholder"
							v-model="content" @confirm="showLogin" />
					</view>
				</view>
			</view>
		</u-popup>

		<u-popup :show="show" @close="show = false" mode="center" round="40rpx">
			<view class="modal">
				<view class="modal_title flex_r_between">
					<text>拒绝原因</text>
					<u-icon name="close-circle" color="#CCCCCC" size="48rpx" @click="show = false"></u-icon>
				</view>
		
				<view class="modal_textarea">
					<textarea placeholder="请输入" placeholder-class="input-placeholder" v-model="check_content"></textarea>
				</view>
		
				<view class="modal_btn flex_r_around" @click="onAccept">
					<text>确定</text>
				</view>
		
			</view>
		</u-popup>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {},

				list: [],
				total: 0,
				page: 1,

				danmuList: [],

				videoContext: null,

				is_play: false,

				show_eval: false,

				content: '',
				
				show: false,
				
				check_content: '',
				
				circle_id: 0,
			}
		},
		methods: {

			preventHandler() {
				return;
			},

			getDetail(article_id) {
				this.$get('/article/getInfo', {
					article_id: article_id,
					is_h5: 1,
				}).then(res => {
					this.data = res.data;
					if (this.data.images) {
						this.data.images = res.data.images.split(',');
					}
					this.getDiscuss();
				})
			},

			getDiscuss() {
				this.$get('/article/getDiscuss', {
					article_id: this.data.id,
					pid: 0,
					page: this.page
				}).then(res => {
					this.total = res.data.total;
					res.data.data.forEach(element => {
						element.child = [];
						element.page = 0;
						this.list.push(element);
					})
				})
			},

			// 控制播放和暂停
			onVideo(e) {
				if (this.is_play) {
					this.videoContext.pause();
				} else {
					this.videoContext.play();
				}
			},

			onReach() {
				if (this.total > this.list.length) {
					this.page++;
					this.getDiscuss();
				}
			},

			showMore(item, index) {
				item.page++;
				this.$get('/article/getDiscuss', {
					article_id: this.data.id,
					pid: item.id,
					page: item.page
				}).then(res => {
					this.list[index].child.push(...res.data.data);
				})
			},

			hideMore(item, index) {
				this.list[index].page = 0;
				this.list[index].child = [];
			},

			beforeAccept(item){
				this.show = true;
			},
			
			onAccept(){
				this.show = false;
				this.$post('/circle.article/setReviewStatus',{
					article_id: this.data.id,
					status: 3,
					check_content: this.check_content,
					circle_id: this.circle_id,
				}).then(res=>{
					this.$util.msg(res.msg);
					this.$util.back();
				})
			},
			
			onAgree(){
				this.$post('/circle.article/setReviewStatus',{
					article_id: this.data.id,
					status: 2,
					circle_id: this.circle_id,
				}).then(res=>{
					this.$util.msg(res.msg);
					this.$util.back();
				})
			},

		},

		onLoad(option) {
			this.circle_id = option.circle_id || 0;
			if (option.id) {
				this.getDetail(option.id);
			}
		},

		onReady() {
			this.videoContext = uni.createVideoContext('myVideo');
		}
	}
</script>

<style lang="less" scoped>
	
	.nav_bar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: calc(var(--paging-head-top) + 44px);
		z-index: 99;
		background: transparent;
		padding: var(--paging-head-top) 32rpx 0 0;
		
		.nav_bar_icon {
			height: 44px;
			padding: 0 32rpx;
		}
		
		.nav_bar_btn {
			.nav_bar_item {
				width: 128rpx;
				height: 52rpx;
				border-radius: 28rpx;
				margin-left: 16rpx;
				text {
					font-weight: 500;
					font-size: 28rpx;
					color: #FFFFFF;
				}
			}
			
			.agree {
				background: #1FC129;
			}
			
			.accept {
				background: #FD2A53;
			}
		}
	}
	
	.page {
		height: 100vh;
		background: #000;
	}

	.box {
		position: fixed;
		top: 0;
		left: 0;
		height: 100vh;
		width: 100vw;
		z-index: 1;

		.video {
			width: 100%;
			height: 100%;
			position: relative;

			video {
				width: 100%;
				height: 100%;
				display: block;
			}

			.play_icon {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateX(-50%);
				width: 80rpx;
				height: 80rpx;
				background: rgba(0, 0, 0, .8);
				border-radius: 40rpx;
			}
		}

		.swiper {
			width: 100%;
			height: 100%;

			.item {
				width: 100%;
				height: 100%;

				image {
					width: 100%;
				}
			}

		}
	}

	.icon {
		width: 20vw;
		position: fixed;
		right: 0;
		bottom: 200rpx;
		z-index: 3;

		.item {
			margin-top: 32rpx;

			image {
				width: 56rpx;
				height: 56rpx;
			}

			text {
				font-size: 28rpx;
				color: #FFFBFB;
				margin-top: 4rpx;
			}
		}
	}

	.container {
		width: 80vw;
		position: fixed;
		left: 0;
		bottom: 100rpx;
		z-index: 3;
		padding: 0 32rpx;

		.address {
			max-width: 320rpx;
			height: 64rpx;
			background: rgba(0, 0, 0, 0.4);
			border-radius: 8rpx;
			padding: 18rpx 20rpx;
			margin-bottom: 24rpx;

			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 12rpx;
			}

			text {
				font-size: 24rpx;
				color: #FFFFFF;
			}
		}

		.user {
			overflow: hidden;

			.avatar {
				width: 98rpx;
				height: 98rpx;
				border-radius: 49rpx;
				overflow: hidden;
				border: 2rpx solid #FFF;

				image {
					width: 98rpx;
					height: 98rpx;
				}
			}

			.nickname {
				font-weight: 500;
				font-size: 40rpx;
				color: #FFFBFB;
				margin: 0 12rpx 0 24rpx;
				max-width: 300rpx;
			}

			.follow {
				width: 32rpx;
				height: 32rpx;
				background: #FD2A53;
				border-radius: 16rpx;
			}
		}

		.content_text {
			margin-top: 30rpx;
			font-size: 28rpx;
			color: #FFFBFB;
			line-height: 40rpx;
		}
	}

	.popup {
		height: 70vh;
		padding: 32rpx 0;
		overflow: hidden;

		.block {
			flex: 1;
			width: 100%;
			padding: 0 32rpx;
		}

		scroll-view {
			height: 100%;
		}

		.list {
			overflow: hidden;
			align-items: flex-start;
			width: 100%;
			margin-bottom: 40rpx;

			.avatar {
				width: 72rpx;
				height: 72rpx;
				border-radius: 72rpx;
				overflow: hidden;
				margin-right: 16rpx;
				background: #D8D8D8;

				image {
					width: 72rpx;
					height: 72rpx;
				}
			}

			.list_content {
				flex: 1;

				.nickname {
					text {
						font-size: 24rpx;
						color: #999999;
						line-height: 34rpx;
						max-width: 300rpx;
					}

					view {
						font-size: 24rpx;
						color: #FFFFFF;
						padding: 0rpx 6rpx;
						background: #FD2A53;
						border-radius: 4rpx;
						margin-left: 8rpx;
					}
				}

				.content {
					font-size: 28rpx;
					color: #333333;
					line-height: 40rpx;
					margin: 4rpx 0;
				}

				.text {
					view {
						font-size: 24rpx;
						color: #999999;
						line-height: 34rpx;
						margin-right: 12rpx;
					}

					text {
						font-size: 24rpx;
						color: #333333;
						line-height: 34rpx;
					}
				}

				.child {
					align-items: flex-start;
					margin-top: 24rpx;

					.child_avatar {
						width: 40rpx;
						height: 40rpx;
						background: #D8D8D8;
						border-radius: 20rpx;
						overflow: hidden;
						margin-right: 16rpx;

						image {
							width: 40rpx;
							height: 40rpx;
						}
					}

					.child_content {
						flex: 1;

						.nickname {
							font-size: 24rpx;
							color: #999999;
							line-height: 34rpx;
						}

						.content {
							font-size: 28rpx;
							color: #333333;
							line-height: 40rpx;
						}

						.text {
							font-size: 24rpx;
							color: #999999;
							line-height: 34rpx;
						}

					}
				}

				.more {
					margin-top: 32rpx;

					.border {
						width: 40rpx;
						height: 2rpx;
						background: #CCCCCC;
					}

					.more_block {
						margin-left: 26rpx;

						text {
							font-size: 24rpx;
							color: #666666;
							line-height: 34rpx;
							margin-right: 6rpx;
						}
					}
				}

			}


		}

		.input {
			padding: 20rpx 32rpx 30rpx;
			width: 750rpx;
			background: #FFFFFF;
			box-shadow: 0rpx -2rpx 0rpx 0rpx rgba(230, 230, 230, 0.5);

			.tag {
				#select {
					background: #FDEFF2;
					border: 2rpx solid #FD2A53;

					text {
						color: #FD2A53;
					}
				}

				.item {
					margin-right: 16rpx;
					width: 176rpx;
					height: 56rpx;
					background: #F1F1F1;
					border-radius: 28rpx;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 6rpx;
					}

					text {
						font-size: 26rpx;
						color: #333333;
						line-height: 32rpx;
					}
				}
			}

			.inp {
				height: 80rpx;
				background: #F1F1F1;
				border-radius: 40rpx;
				padding: 0 24rpx;
				margin-top: 20rpx;

				input {
					width: 100%;
					font-size: 28rpx;
					color: #333;
				}
			}
		}
	}

	.modal {
		width: 616rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		padding: 34rpx 16rpx 38rpx 32rpx;
	
		.modal_title {
			text {
				font-weight: 500;
				font-size: 36rpx;
				color: #131313;
				line-height: 50rpx;
			}
		}
	
		.modal_textarea {
			width: 552rpx;
			height: 208rpx;
			background: #F7F7F7;
			border-radius: 16rpx;
			padding: 24rpx;
			margin: 32rpx 0;
			overflow: hidden;
	
			textarea {
				font-size: 28rpx;
				color: #333;
				line-height: 36rpx;
			}
		}
	
		.modal_btn {
			width: 320rpx;
			height: 88rpx;
			background: #FD2A53;
			border-radius: 44rpx;
			margin: 0 auto;
	
			text {
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	
	}

</style>